//===--- Passes.def - Swift SILPass Metaprogramming -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with SILPasses.
//
//===----------------------------------------------------------------------===//

/// PASS(Id, Tag, Description)
///   Id is a pass "identifier", used for its enum case, PassKind::Id,
///   and type name, as returned by the global function swift::create##Id().
///
///   Tag identifies the pass as a command-line compatible option string.
///
///   Description is a short description of the pass.
///
///   Id and Tag are unique identifiers which may be used in test
///   cases and tools to specify a pass by string. Different tools simply prefer
///   different identifier formats. Changing any of one these strings may change
///   the functionality of some tests.
///
///   This macro must be defined by the includer.
#ifndef PASS
#error "Macro must be defined by includer"
#endif

/// IRGEN_PASS(Id, Tag, Description)
///   This macro follows the same conventions as PASS(Id, Tag, Description),
///   but is used for IRGen passes which are built outside of the
///   SILOptimizer library.
///   
///   An IRGen pass is created by IRGen and needs to be registered with the pass
///   manager dynamically.
#ifndef IRGEN_PASS
#define IRGEN_PASS(Id, Tag, Description) PASS(Id, Tag, Description)
#endif

/// PASS_RANGE(RANGE_ID, START, END)
///   Pass IDs between PassKind::START and PassKind::END, inclusive,
///   fall within the set known as
#ifndef PASS_RANGE
#define PASS_RANGE(Id, First, Last)
#endif

PASS(AADumper, "aa-dump",
     "Dump Alias Analysis over all Pairs")
PASS(ABCOpt, "abcopts",
     "Array Bounds Check Optimization")
PASS(AccessEnforcementDom, "access-enforcement-dom",
     "Remove dominated access checks with no nested conflict")
PASS(AccessEnforcementOpts, "access-enforcement-opts",
     "Access Enforcement Optimization")
PASS(AccessEnforcementReleaseSinking, "access-enforcement-release",
     "Access Enforcement Release Sinking")
PASS(AccessEnforcementSelection, "access-enforcement-selection",
     "Access Enforcement Selection")
PASS(AccessEnforcementWMO, "access-enforcement-wmo",
     "Access Enforcement Whole Module Optimization")
PASS(CrossModuleSerializationSetup, "cross-module-serialization-setup",
     "Setup serialization flags for cross-module optimization")
PASS(AccessSummaryDumper, "access-summary-dump",
     "Dump Address Parameter Access Summary")
PASS(AccessedStorageAnalysisDumper, "accessed-storage-analysis-dump",
     "Dump Accessed Storage Analysis Summaries")
PASS(AccessPathVerification, "access-path-verification",
     "Verify Access Paths (and Accessed Storage)")
PASS(AccessedStorageDumper, "accessed-storage-dump",
     "Dump Accessed Storage Information")
PASS(AccessMarkerElimination, "access-marker-elim",
     "Access Marker Elimination.")
PASS(AddressLowering, "address-lowering",
     "SIL Address Lowering")
PASS(AllocBoxToStack, "allocbox-to-stack",
     "Stack Promotion of Box Objects")
IRGEN_PASS(AllocStackHoisting, "alloc-stack-hoisting",
           "SIL alloc_stack Hoisting")
PASS(ArrayCountPropagation, "array-count-propagation",
     "Array Count Propagation")
PASS(ArrayElementPropagation, "array-element-propagation",
     "Array Element Propagation")
PASS(AssumeSingleThreaded, "sil-assume-single-threaded",
     "Assume Single-Threaded Environment")
PASS(BasicInstructionPropertyDumper, "basic-instruction-property-dump",
     "Print SIL Instruction MemBehavior and ReleaseBehavior Information")
PASS(BasicCalleePrinter, "basic-callee-printer",
     "Print Basic Callee Analysis for Testing")
PASS(CFGPrinter, "view-cfg",
     "View Function CFGs")
PASS(COWArrayOpts, "cowarray-opt",
     "COW Array Optimization")
PASS(CSE, "cse",
     "Common Subexpression Elimination")
PASS(CallerAnalysisPrinter, "caller-analysis-printer",
     "Print Caller Analysis for Testing")
PASS(CapturePromotion, "capture-promotion",
     "Capture Promotion to Eliminate Escaping Boxes")
PASS(CapturePropagation, "capture-prop",
     "Captured Constant Propagation")
PASS(ClosureSpecializer, "closure-specialize",
     "Closure Specialization on Constant Function Arguments")
PASS(ClosureLifetimeFixup, "closure-lifetime-fixup",
     "Closure Lifetime Fixup")
PASS(CodeSinking, "code-sinking",
     "Code Sinking")
PASS(ComputeDominanceInfo, "compute-dominance-info",
     "Compute Dominance Information for Testing")
PASS(ComputeLoopInfo, "compute-loop-info",
     "Compute Loop Information for Testing")
PASS(ConditionForwarding, "condition-forwarding",
     "Conditional Branch Forwarding to Fold SIL switch_enum")
PASS(ConstantEvaluatorTester, "test-constant-evaluator",
      "Test constant evaluator")
PASS(ConstantEvaluableSubsetChecker, "test-constant-evaluable-subset",
     "Test Swift code snippets expected to be constant evaluable")
PASS(CopyForwarding, "copy-forwarding",
     "Copy Forwarding to Remove Redundant Copies")
PASS(CopyPropagation, "copy-propagation",
     "Copy propagation to Remove Redundant SSA Copies, pruning debug info")
PASS(MandatoryCopyPropagation, "mandatory-copy-propagation",
     "Copy propagation to Remove Redundant SSA Copies, preserving debug info")
PASS(COWOpts, "cow-opts",
     "Optimize COW operations")
PASS(Differentiation, "differentiation",
     "Automatic Differentiation")
PASS(EpilogueARCMatcherDumper, "sil-epilogue-arc-dumper",
     "Print Epilogue retains of Returned Values and Argument releases")
PASS(EpilogueRetainReleaseMatcherDumper, "sil-epilogue-retain-release-dumper",
     "Print Epilogue retains of Returned Values and Argument releases")
PASS(RedundantOverflowCheckRemoval, "remove-redundant-overflow-checks",
     "Redundant Overflow Check Removal")
PASS(DCE, "dce",
     "Dead Code Elimination")
PASS(DeadArgSignatureOpt, "dead-arg-signature-opt",
     "Dead Argument Elimination via Function Specialization")
PASS(DeadFunctionElimination, "sil-deadfuncelim",
     "Dead Function Elimination")
PASS(DeadObjectElimination, "deadobject-elim",
     "Dead Object Elimination for Classes with Trivial Destruction")
PASS(DefiniteInitialization, "definite-init",
     "Definite Initialization for Diagnostics")
PASS(DestroyHoisting, "destroy-hoisting",
     "Hoisting of value destroys")
PASS(Devirtualizer, "devirtualizer",
     "Indirect Call Devirtualization")
PASS(DiagnoseInfiniteRecursion, "diagnose-infinite-recursion",
     "Diagnose Infinitely-Recursive Code")
PASS(DiagnoseInvalidEscapingCaptures, "diagnose-invalid-escaping-captures",
     "Diagnose Invalid Escaping Captures")
PASS(DiagnoseStaticExclusivity, "diagnose-static-exclusivity",
     "Static Enforcement of Law of Exclusivity")
PASS(DiagnoseUnreachable, "diagnose-unreachable",
     "Diagnose Unreachable Code")
PASS(DiagnosticConstantPropagation, "diagnostic-constant-propagation",
     "Constants Propagation for Diagnostics")
PASS(DifferentiabilityWitnessDevirtualizer,
     "differentiability-witness-devirtualizer",
     "Inlines Differentiability Witnesses")
PASS(EagerSpecializer, "eager-specializer",
     "Eager Specialization via @_specialize")
PASS(OnonePrespecializations, "onone-prespecializer",
     "Pre specialization via @_specialize")
PASS(EarlyCodeMotion, "early-codemotion",
     "Early Code Motion without Release Hoisting")
PASS(EarlyInliner, "early-inline",
     "Early Inlining Preserving Semantic Functions")
PASS(EmitDFDiagnostics, "dataflow-diagnostics",
     "Emit SIL Diagnostics")
PASS(EscapeAnalysisDumper, "escapes-dump",
     "Dump Escape Analysis Results")
PASS(FunctionOrderPrinter, "function-order-printer",
     "Print Function Order for Testing")
PASS(FunctionSignatureOpts, "function-signature-opts",
     "Function Signature Optimization")
PASS(ARCSequenceOpts, "arc-sequence-opts",
     "ARC Sequence Optimization")
PASS(ARCLoopOpts, "arc-loop-opts",
     "ARC Loop Optimization")
PASS(EarlyRedundantLoadElimination, "early-redundant-load-elim",
     "Early Redundant Load Elimination")
PASS(RedundantLoadElimination, "redundant-load-elim",
     "Redundant Load Elimination")
PASS(DeadStoreElimination, "dead-store-elim",
     "Dead Store Elimination")
PASS(GenericSpecializer, "generic-specializer",
     "Generic Function Specialization on Static Types")
PASS(ExistentialSpecializer, "existential-specializer",
     "Existential Specializer")
PASS(SILSkippingChecker, "check-sil-skipping",
     "Utility pass to ensure -experimental-skip-*-function-bodies skip "
     "SIL generation of not-to-be-serialized functions entirely")
PASS(GlobalOpt, "global-opt",
     "SIL Global Optimization")
PASS(GlobalPropertyOpt, "global-property-opt",
     "Global Property Optimization")
PASS(GuaranteedARCOpts, "guaranteed-arc-opts",
     "Guaranteed ARC Optimization")
PASS(HighLevelCSE, "high-level-cse",
     "Common Subexpression Elimination on High-Level SIL")
PASS(HighLevelLICM, "high-level-licm",
     "Loop Invariant Code Motion in High-Level SIL")
PASS(IVInfoPrinter, "iv-info-printer",
     "Print Induction Variable Information for Testing")
PASS(OptimizeHopToExecutor, "optimize-hop-to-executor",
     "Optimize hop_to_executor instructions for actor isolated code")
PASS(InstCount, "inst-count",
     "Record SIL Instruction, Block, and Function Counts as LLVM Statistics")
PASS(JumpThreadSimplifyCFG, "jumpthread-simplify-cfg",
     "Simplify CFG via Jump Threading")
PASS(LetPropertiesOpt, "let-properties-opt",
     "Let Property Optimization")
PASS(LICM, "licm",
     "Loop Invariant Code Motion")
PASS(LateCodeMotion, "late-codemotion",
     "Late Code Motion with Release Hoisting")
PASS(LateDeadFunctionElimination, "late-deadfuncelim",
     "Late Dead Function Elimination")
PASS(LateInliner, "late-inline",
     "Late Function Inlining")
PASS(LoopCanonicalizer, "loop-canonicalizer",
     "Loop Canonicalization")
PASS(LoopInfoPrinter, "loop-info-printer",
     "Print Loop Information for Testing")
PASS(LoopRegionViewText, "loop-region-view-text",
     "Print Loop Region Information for Testing")
PASS(LoopRegionViewCFG, "loop-region-view-cfg",
     "View Loop Region CFG")
PASS(LoopRotate, "loop-rotate",
     "Loop Rotation")
PASS(LoopUnroll, "loop-unroll",
     "Loop Unrolling")
PASS(LowerAggregateInstrs, "lower-aggregate-instrs",
     "Lower Aggregate SIL Instructions to Multiple Scalar Operations")
PASS(MandatoryInlining, "mandatory-inlining",
     "Mandatory Inlining of Transparent Functions")
PASS(Mem2Reg, "mem2reg",
     "Memory to SSA Value Conversion to Remove Stack Allocation")
PASS(MemBehaviorDumper, "mem-behavior-dump",
     "Print SIL Instruction MemBehavior from Alias Analysis over all Pairs")
PASS(LSLocationPrinter, "lslocation-dump",
     "Print Load-Store Location Results Covering all Accesses")
PASS(MergeCondFails, "merge-cond_fails",
     "Merge SIL cond_fail to Eliminate Redundant Overflow Checks")
PASS(MoveCondFailToPreds, "move-cond-fail-to-preds",
     "Move SIL cond_fail by Hoisting Checks")
PASS(NoReturnFolding, "noreturn-folding",
     "Prune Control Flow at No-Return Calls Using SIL unreachable")
PASS(ObjectOutliner, "object-outliner",
     "Outlining of Global Objects")
PASS(Outliner, "outliner",
     "Function Outlining Optimization")
PASS(OwnershipModelEliminator, "ownership-model-eliminator",
     "Eliminate Ownership Annotation of SIL")
PASS(NestedSemanticFunctionCheck, "nested-semantic-function-check",
     "Diagnose improperly nested '@_semantics' functions")
PASS(NonTransparentFunctionOwnershipModelEliminator,
     "non-transparent-func-ownership-model-eliminator",
     "Eliminate Ownership Annotations from non-transparent SIL Functions")
PASS(NonStdlibNonTransparentFunctionOwnershipModelEliminator,
     "non-stdlib-non-transparent-func-ownership-model-eliminator",
     "Eliminate Ownership Annotations from non-transparent SIL Functions only when not processing the stdlib.")
PASS(RCIdentityDumper, "rc-id-dumper",
     "Print Reference Count Identities")
PASS(AlwaysInlineInliner, "always-inline",
     "Inline always inline functions")
PASS(PerfInliner, "inline",
     "Performance Function Inlining")
PASS(PerformanceConstantPropagation, "performance-constant-propagation",
     "Constant Propagation for Performance without Diagnostics")
PASS(PredictableMemoryAccessOptimizations, "predictable-memaccess-opts",
     "Predictable Memory Access Optimizations for Diagnostics")
PASS(PredictableDeadAllocationElimination, "predictable-deadalloc-elim",
     "Eliminate dead temporary allocations after diagnostics")
PASS(RedundantPhiElimination, "redundant-phi-elimination",
     "Redundant Phi Block Argument Elimination")
PASS(PhiExpansion, "phi-expansion",
     "Replace Phi arguments by their only used field")
PASS(ReleaseDevirtualizer, "release-devirtualizer",
     "SIL release Devirtualization")
PASS(RetainSinking, "retain-sinking",
     "SIL retain Sinking")
PASS(ReleaseHoisting, "release-hoisting",
     "SIL release Hoisting")
PASS(LateReleaseHoisting, "late-release-hoisting",
     "Late SIL release Hoisting Preserving Epilogues")
IRGEN_PASS(LoadableByAddress, "loadable-address",
     "SIL Large Loadable type by-address lowering.")
PASS(MandatorySILLinker, "mandatory-linker",
     "Deserialize all referenced SIL functions that are shared or transparent")
PASS(PerformanceSILLinker, "performance-linker",
     "Deserialize all referenced SIL functions")
PASS(RawSILInstLowering, "raw-sil-inst-lowering",
     "Lower all raw SIL instructions to canonical equivalents.")
PASS(TempLValueOpt, "temp-lvalue-opt",
     "Remove short-lived immutable temporary l-values")
PASS(TempRValueOpt, "temp-rvalue-opt",
     "Remove short-lived immutable temporary copies")
PASS(SideEffectsDumper, "side-effects-dump",
     "Print Side-Effect Information for all Functions")
PASS(IRGenPrepare, "irgen-prepare",
     "Cleanup SIL in preparation for IRGen")
PASS(SILGenCleanup, "silgen-cleanup",
     "Cleanup SIL in preparation for diagnostics")
PASS(SILCombine, "sil-combine",
     "Combine SIL Instructions via Peephole Optimization")
PASS(SILDebugInfoGenerator, "sil-debuginfo-gen",
     "Generate Debug Information with Source Locations into Textual SIL")
PASS(EarlySROA, "early-sroa",
     "Scalar Replacement of Aggregate Stack Objects on high-level SIL")
PASS(SROA, "sroa",
     "Scalar Replacement of Aggregate Stack Objects")
PASS(SROABBArgs, "sroa-bb-args",
     "Scalar Replacement of Aggregate SIL Block Arguments")
PASS(SimplifyBBArgs, "simplify-bb-args",
     "SIL Block Argument Simplification")
PASS(SimplifyCFG, "simplify-cfg",
     "SIL CFG Simplification")
PASS(SpeculativeDevirtualization, "specdevirt",
     "Speculative Devirtualization via Guarded Calls")
PASS(SplitAllCriticalEdges, "split-critical-edges",
     "Split all Critical Edges in the SIL CFG")
PASS(SplitNonCondBrCriticalEdges, "split-non-cond_br-critical-edges",
     "Split all Critical Edges not from SIL cond_br")
PASS(StackPromotion, "stack-promotion",
     "Stack Promotion of Class Objects")
PASS(StripDebugInfo, "strip-debug-info",
     "Strip Debug Information")
PASS(StringOptimization, "string-optimization",
     "Optimization for String operations")
PASS(SwiftArrayPropertyOpt, "array-property-opt",
     "Loop Specialization for Array Properties")
PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
     "SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")
PASS(UsePrespecialized, "use-prespecialized",
     "Use Pre-Specialized Functions")
PASS(OwnershipDumper, "ownership-dumper",
     "Print Ownership information for Testing")
PASS(OwnershipVerifierTextualErrorDumper, "ownership-verifier-textual-error-dumper",
     "Run ownership verification on all functions, emitting FileCheck-able textual errors instead of asserting")
PASS(SemanticARCOpts, "semantic-arc-opts",
     "Semantic ARC Optimization")
PASS(SimplifyUnreachableContainingBlocks, "simplify-unreachable-containing-blocks",
     "Utility pass. Removes all non-term insts from blocks with unreachable terms")
PASS(SerializeSILPass, "serialize-sil",
     "Utility pass. Serializes the current SILModule")
PASS(CMOSerializeSILPass, "cmo-serialize-sil",
     "Utility pass. Serializes the current SILModule for cross-module-optimization")
PASS(YieldOnceCheck, "yield-once-check",
    "Check correct usage of yields in yield-once coroutines")
PASS(OSLogOptimization, "os-log-optimization", "Optimize os log calls")
PASS(ForEachLoopUnroll, "for-each-loop-unroll",
     "Unroll forEach loops over array literals")
PASS(MandatoryCombine, "mandatory-combine",
    "Perform mandatory peephole combines")
PASS(OptimizedMandatoryCombine, "optimized-mandatory-combine",
    "Perform -O level mandatory peephole combines")
PASS(BugReducerTester, "bug-reducer-tester",
     "sil-bug-reducer Tool Testing by Asserting on a Sentinel Function")
PASS(OptRemarkGenerator, "sil-opt-remark-generator",
     "Emit small peephole opt remarks that do not use large analyses")
PASS(PruneVTables, "prune-vtables",
     "Mark class methods that do not require vtable dispatch")
PASS_RANGE(AllPasses, AADumper, PruneVTables)

#undef IRGEN_PASS
#undef PASS
#undef PASS_RANGE
